package com.example.dbmysql.service.impl;

import com.example.dbmysql.pojo.User;
import com.example.dbmysql.mapper.UserMapper;
import com.example.dbmysql.service.UserService;
import com.example.dbmysql.utils.Md5Util;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;


@Service
public class userServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public User findByUserName(String username) {

       User u = userMapper.findByUserName(username);

        return u;
    }

    @Override
    public void register(String username, String password) {

        // 密码需要加密

     String md5String =   Md5Util.getMD5String(password);

     // 添加
        userMapper.add(username,md5String);
    }

    @Override
    public User update(@NotNull User user) {
        // 添加参数前需要把更新时间先更新
        user.setUpdateTimer(LocalDateTime.now());
        userMapper.update(user);
        return user;
    }

    @Override
    public void delUserById(User user) {
        userMapper.DelUser(user);
    }
}
